<template>
  <u-select
      ref="select"
      v-model="show"
      mode="single-column"
      :list="list"
      child-name="children"
      @confirm="confirm"
      :default-value="defaultList"
  ></u-select>
</template>

<script>
import {getDictItemstList} from '@/api/dict'
export default {
  data(){
    return {
      show: false, //展示所在地区数据
      cityIndex: 0, //所在城区索引
      list: [],//城市
      defaultList:[],//第几个
    }
  },
  mounted(){
    this.getDictItems('new_area_code')
  },
  methods:{
    //确认地址
    confirm(data){
      const [a] = data
      const index = this.list.findIndex((item) =>item.value === a.value)
      this.defaultList = [index]
      this.$emit('confirm',a)
    },
    //地区编码
    async getDictItems() {
      const { code, result } = await getDictItemstList({
        dictCode: 'new_area_code',
        sign: '',
      })
      if (code === 0) {
        const paramsList = []
        if (result.length) {
          result.map((item, index) => {
            const { text: label, value } = item
            paramsList.push({
              value,
              label,
              index,
            })
          })
          this.list = paramsList
          this.list.push({
            subText: "",
            label: "全部城区",
            title: "全部城区",
            value: "",
          })
        }
        this.$emit('loading',this.list)
      }
    },
  }
}
</script>

<style>
</style>
